using System.Collections.ObjectModel;
using CodePlex.DnD4eCampaignManager.DnD4e.Interfaces;
using CodePlex.DnD4eCampaignManager.Presentation.ViewInterfaces;
using CodePlex.DnD4eCampaignManager.Repositories.Interfaces;

namespace CodePlex.DnD4eCampaignManager.Presentation
{
    public class PlayerCharacterPresenter
    {
        public PlayerCharacterPresenter(string playerCharacterName, IPlayerCharacterView view, IPlayerCharacterRepository playerCharacterRepository)
        {
            PlayerCharacterName = playerCharacterName;
            View = view;
            PlayerCharacterRepository = playerCharacterRepository;
            DisplayedPlayerCharacter = PlayerCharacterRepository.GetByName(PlayerCharacterName);
        }

        public string PlayerCharacterName { get; set; }
        public IPlayerCharacterRepository PlayerCharacterRepository { get; set; }
        public IPlayerCharacterView View { get; set; }
        private IPlayerCharacter DisplayedPlayerCharacter { get; set; }

        public void DisplayPlayerCharacter()
        {
            View.CharacterName = PlayerCharacterName;
            ReadOnlyCollection<string> playerCharacterNames = PlayerCharacterRepository.GetAllNames();
            if ( !playerCharacterNames.Contains(PlayerCharacterName) )
            {
                return;
            }
            DisplayedPlayerCharacter = PlayerCharacterRepository.GetByName(PlayerCharacterName);
            PushBasicDataToView();
            PushAbilityDataToView();
            PushHealthToView();
            PushDefensesToView();
            PushInitiativeToView();
            PushMovementToView();
            PushSensesToView();
            PushPowersToView();
            PushSkillsToView();
        }

        public void SavePlayerCharacter()
        {
            PullBasicDataFromView();
            PullAbilityDataFromView();
            PullHitPointDataFromView();
            PullDefenseDataFromView();
            PullSurgesDataFromView();
            PullInitiativeDataFromView();
            PullMovementDataFromView();
            PullSensesDataFromView();
            PullPowersDataFromView();
            PlayerCharacterRepository.Save(DisplayedPlayerCharacter);
        }

        private void PullAbilityDataFromView()
        {
            DisplayedPlayerCharacter.AbilityStrength = View.AbilityStrength;
            DisplayedPlayerCharacter.AbilityConstitution = View.AbilityConstitution;
            DisplayedPlayerCharacter.AbilityDexterity = View.AbilityDexterity;
            DisplayedPlayerCharacter.AbilityIntelligence = View.AbilityIntelligence;
            DisplayedPlayerCharacter.AbilityWisdom = View.AbilityWisdom;
            DisplayedPlayerCharacter.AbilityCharisma = View.AbilityCharisma;
        }

        private void PullBasicDataFromView()
        {
            DisplayedPlayerCharacter.CharacterClass = View.CharacterClass;
            DisplayedPlayerCharacter.CharacterParagonPath = View.CharacterParagonPath;
            DisplayedPlayerCharacter.CharacterEpicDestiny = View.CharacterEpicDestiny;
            DisplayedPlayerCharacter.CharacterExperiencePoints = View.CharacterExperiencePoints;
            DisplayedPlayerCharacter.CharacterRace = View.CharacterRace;
            DisplayedPlayerCharacter.CreatureSize = View.CreatureSize;
            DisplayedPlayerCharacter.CharacterAge = View.CharacterAge;
            DisplayedPlayerCharacter.CharacterGender = View.CharacterGender;
            DisplayedPlayerCharacter.CharacterHeight = View.CharacterHeight;
            DisplayedPlayerCharacter.CharacterWeight = View.CharacterWeight;
            DisplayedPlayerCharacter.CharacterAlignment = View.CharacterAlignment;
            DisplayedPlayerCharacter.CharacterDeity = View.CharacterDeity;
        }

        private void PullDefenseDataFromView()
        {
            DisplayedPlayerCharacter.DefenseArmorClass = View.DefenseArmorClass;
            DisplayedPlayerCharacter.DefenseFortitude = View.DefenseFortitude;
            DisplayedPlayerCharacter.DefenseReflex = View.DefenseReflex;
            DisplayedPlayerCharacter.DefenseWillpower = View.DefenseWillpower;
        }

        private void PullHitPointDataFromView()
        {
            DisplayedPlayerCharacter.HitPointsMaximum = View.HitPointsMaximum;
            DisplayedPlayerCharacter.HitPointsCurrent = View.HitPointsCurrent;
        }

        private void PullInitiativeDataFromView()
        {
            DisplayedPlayerCharacter.InitiativeModifier = View.InitiativeModifier;
        }

        private void PullMovementDataFromView()
        {
            DisplayedPlayerCharacter.MovementSpeed = View.MovementSpeed;
            DisplayedPlayerCharacter.MovementSpeedOther = View.MovementSpeedOther;
        }

        private void PullPowersDataFromView()
        {
            DisplayedPlayerCharacter.PowersAtWill = View.PowersAtWill;
            DisplayedPlayerCharacter.PowersEncounter = View.PowersEncounter;
            DisplayedPlayerCharacter.PowersDaily = View.PowersDaily;
            DisplayedPlayerCharacter.CharacterRituals = View.CharacterRituals;
            DisplayedPlayerCharacter.SpecialQualities = View.SpecialQualities;
            DisplayedPlayerCharacter.CharacterFeats = View.CharacterFeats;
            DisplayedPlayerCharacter.Conditions = View.Conditions;
        }

        private void PullSensesDataFromView()
        {
            DisplayedPlayerCharacter.SensesOther = View.SensesOther;
        }

        private void PullSurgesDataFromView()
        {
            DisplayedPlayerCharacter.HealingSurgesMaximum = View.HealingSurgesMaximum;
            DisplayedPlayerCharacter.HealingSurgesCurrent = View.HealingSurgesCurrent;
        }

        private void PushAbilityDataToView()
        {
            View.AbilityStrength = DisplayedPlayerCharacter.AbilityStrength;
            View.AbilityConstitution = DisplayedPlayerCharacter.AbilityConstitution;
            View.AbilityDexterity = DisplayedPlayerCharacter.AbilityDexterity;
            View.AbilityIntelligence = DisplayedPlayerCharacter.AbilityIntelligence;
            View.AbilityWisdom = DisplayedPlayerCharacter.AbilityWisdom;
            View.AbilityCharisma = DisplayedPlayerCharacter.AbilityCharisma;
        }

        private void PushBasicDataToView()
        {
            View.CharacterLevel = DisplayedPlayerCharacter.CharacterLevel;
            View.CharacterClass = DisplayedPlayerCharacter.CharacterClass;
            View.CharacterParagonPath = DisplayedPlayerCharacter.CharacterParagonPath;
            View.CharacterEpicDestiny = DisplayedPlayerCharacter.CharacterEpicDestiny;
            View.CharacterExperiencePoints = DisplayedPlayerCharacter.CharacterExperiencePoints;
            View.CharacterRace = DisplayedPlayerCharacter.CharacterRace;
            View.CreatureSize = DisplayedPlayerCharacter.CreatureSize;
            View.CharacterAge = DisplayedPlayerCharacter.CharacterAge;
            View.CharacterGender = DisplayedPlayerCharacter.CharacterGender;
            View.CharacterHeight = DisplayedPlayerCharacter.CharacterHeight;
            View.CharacterWeight = DisplayedPlayerCharacter.CharacterWeight;
            View.CharacterAlignment = DisplayedPlayerCharacter.CharacterAlignment;
            View.CharacterDeity = DisplayedPlayerCharacter.CharacterDeity;
        }

        private void PushDefensesToView()
        {
            View.DefenseArmorClass = DisplayedPlayerCharacter.DefenseArmorClass;
            View.DefenseFortitude = DisplayedPlayerCharacter.DefenseFortitude;
            View.DefenseReflex = DisplayedPlayerCharacter.DefenseReflex;
            View.DefenseWillpower = DisplayedPlayerCharacter.DefenseWillpower;
        }

        private void PushHealthToView()
        {
            View.HealingSurgesMaximum = DisplayedPlayerCharacter.HealingSurgesMaximum;
            View.HealingSurgesCurrent = DisplayedPlayerCharacter.HealingSurgesCurrent;
            View.HealingSurgeValue = DisplayedPlayerCharacter.HealingSurgeValue;
            View.HitPointsCurrent = DisplayedPlayerCharacter.HitPointsCurrent;
            View.HitPointsMaximum = DisplayedPlayerCharacter.HitPointsMaximum;
            View.HitPointsTemporary = DisplayedPlayerCharacter.HitPointsTemporary;
        }

        private void PushInitiativeToView()
        {
            View.InitiativeModifier = DisplayedPlayerCharacter.InitiativeModifier;
        }

        private void PushMovementToView()
        {
            View.MovementSpeed = DisplayedPlayerCharacter.MovementSpeed;
            View.MovementSpeedOther = DisplayedPlayerCharacter.MovementSpeedOther;
        }

        private void PushPowersToView()
        {
            View.PowersAtWill = DisplayedPlayerCharacter.PowersAtWill;
            View.PowersEncounter = DisplayedPlayerCharacter.PowersEncounter;
            View.PowersDaily = DisplayedPlayerCharacter.PowersDaily;
            View.CharacterRituals = DisplayedPlayerCharacter.CharacterRituals;
            View.SpecialQualities = DisplayedPlayerCharacter.SpecialQualities;
            View.CharacterFeats = DisplayedPlayerCharacter.CharacterFeats;
            View.Conditions = DisplayedPlayerCharacter.Conditions;
        }

        private void PushSensesToView()
        {
            View.SensesPerceptionPassive = DisplayedPlayerCharacter.SensesPerceptionPassive;
            View.SensesPerception = DisplayedPlayerCharacter.SensesPerception;
            View.SensesInsightPassive = DisplayedPlayerCharacter.SensesInsightPassive;
            View.SensesInsight = DisplayedPlayerCharacter.SensesInsight;
            View.SensesOther = DisplayedPlayerCharacter.SensesOther;
        }

        private void PushSkillsToView()
        {
            View.SensesInsight = DisplayedPlayerCharacter.SensesInsight;
            View.SensesPerception = DisplayedPlayerCharacter.SensesPerception;
            View.MovementStealth = DisplayedPlayerCharacter.MovementStealth;
        }
    }
}